package com.xja.service.impl;

import com.xja.common.JsonBean;
import com.xja.entity.SysRole;
import com.xja.mapper.SysRoleMapper;
import com.xja.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author CHENCHEN
 * @company 北京学佳澳教育科技
 * @create 2024-01-15 10:20
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public JsonBean getRoleList() {
        return new JsonBean(0, "ok", sysRoleMapper.selectList());
    }

    @Override
    public JsonBean selectById(Integer id) {
        return new JsonBean(0, "ok", sysRoleMapper.selectByPrimaryKey(id));
    }

    @Override
    public JsonBean deleteById(Integer id) {
        JsonBean jsonBean = new JsonBean(-1, "fail", null);
        int i = sysRoleMapper.deleteByPrimaryKey(id);
        if(i>0){
            jsonBean = new JsonBean(0, "ok", null);
        }
        return jsonBean;
    }

    @Override
    public JsonBean insertRole(SysRole sysRole) {
        JsonBean jsonBean = new JsonBean(-1, "fail", null);
        int i = sysRoleMapper.insert(sysRole);
        if(i>0){
            jsonBean = new JsonBean(0, "ok", null);
        }
        return jsonBean;
    }

    @Override
    public JsonBean updateRole(SysRole sysRole) {
        JsonBean jsonBean = new JsonBean(-1, "fail", null);
        int i = sysRoleMapper.updateByPrimaryKeySelective(sysRole);
        if(i>0){
            jsonBean = new JsonBean(0, "ok", null);
        }
        return jsonBean;
    }

    @Override
    public JsonBean getRoleListByDeptId(Integer deptId) {

        return new JsonBean(0, "ok", sysRoleMapper.getListByDeptId(deptId));
    }
}
